import os, sys

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + '../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'riscv_build_dataset.settings')

import django

django.setup()

from obs.models import obs_package, obs_project

def all_project():
    packages = obs_package.objects.all()
    package_names = [p.package_name for p in packages]
    package_names = list(set(package_names))
    print(len(package_names))
    return package_names

def project_diff(project1, project2):
    p1 = obs_project.objects.get(project_name=project1)
    p2 = obs_project.objects.get(project_name=project2)

    packages1 = obs_package.objects.filter(project=p1)
    packages2 = obs_package.objects.filter(project=p2)

    package_names1 = [p.package_name for p in packages1]
    package_names2 = [p.package_name for p in packages2]

    set1 = set(package_names1)
    set2 = set(package_names2)
    intersection = list(set1 & set2)
    diff = list(set1 ^ set2)

    print(packages1.count(), packages2.count(), len(intersection), len(diff))
    print(*diff, sep='\n')

if __name__ == '__main__':
    all_packages = all_project()
    project1 = 'openEuler:Mainline:RISC-V'
    project2 = 'openEuler:23.09:RISC-V'
    project_diff(project1, project2)